<?php
/**
 * 发件箱
 * @author Administrator
 *
 */
class Application_Model_DbTable_Mailoutbox extends Application_Model_DbTable_Base
{
    protected $_name = 'mail_outbox';
    
    /**
     * 根据id获取详情
     * @param int $id
     */
    public function viewMailById($id){
    	$mail =	$this->fetchRow(" `id`={$id} ");    	
    	if ($mail){
    		$mail = $mail->toArray();
    		$mail["from_name"]  = $mail["from"];
	    	$mail["send_time"]  = date("Y-m-d H:i:s",$mail["create_time"]);
	    	if(!empty($mail["attachment"])){
		    	$mail["attachment"] = array(
		    		"isOutBox" => TRUE,
		    		"name" => $mail["attachment_name"],
		    		"file" => $mail["attachment"],
		    		"mime" => $mail["attachment_mime"] 
		    	);
	    	}
	    	$mail["body"] 		= $mail["mail"];
    	}
    	return $mail;
    }
    
    /**
     * 全部等待发送的邮件
     * @return array
     */
    public function getAllSending()
    {
    	return $this->fetchAll(" `state_send` = 0 ");
    }
    
	/**
     * 全部发送失败的邮件
     * @return array
     */
    public function getAllFailed()
    {
    	return $this->fetchAll(" `state_send` = -1 ");
    }
    
	/**
     * 全部发送可发送的
     * @return array
     */
    public function getAllNeedSend()
    {
    	return $this->fetchAll(" `state_send` < 1 ");
    }
    
	/**
     * 全部发送成功的
     * @return array
     */
    public function getAllSuccess()
    {
    	return $this->fetchAll(" `state_send` = 1 ");
    }
}

